package service

import (
	"blog_server/internal/model/entity"
	"blog_server/internal/model/request"
)

func (svc *Service) CreateTag(param *request.TagRequest) error {
	return svc.dao.CreateTag(param)
}

func (svc *Service) GetArticleTagAmount() (uint, uint, error) {
	articlesCnt, err := svc.dao.CountArticles()
	if err != nil {
		return 0, 0, err
	}
	tagsCnt, err := svc.dao.CountTags()
	if err != nil {
		return 0, 0, err
	}
	return articlesCnt, tagsCnt, nil
}

func (svc *Service) GetTagsByPagination(page, pageSize int) ([]entity.Tag, uint, error) {
	countTags, err := svc.dao.CountTags()
	if err != nil {
		return nil, 0, err
	}
	list, err := svc.dao.GetTagsByPagination(page, pageSize)
	if err != nil {
		return nil, countTags, err
	}
	return list, countTags, nil
}

func (svc *Service) UpdateTag(id uint, param *request.TagRequest) error {
	return svc.dao.UpdateTag(&entity.Tag{
		ID:      id,
		TagName: param.TagName,
		TagDes:  param.Des,
	})
}

func (svc *Service) DeleteTag(id uint) error {
	return svc.dao.DeleteTag(&entity.Tag{ID: id})
}

func (svc Service) GetTagListBySearchText(text string) ([]entity.Tag, error) {
	return svc.dao.GetTagsBySearchText(text)
}

func (svc Service) GetAllTags() ([]entity.Tag, error) {
	return svc.dao.GetAllTags()
}
